package com.xqb.modules.controller.exam;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.ExaQuestionDetail;
import com.xqb.modules.service.IExaQuestionDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 题目信息Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/exam/detail")
public class ExaQuestionDetailController extends BaseController
{
    @Autowired
    private IExaQuestionDetailService exaQuestionDetailService;

    /**
     * 查询题目信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExaQuestionDetail exaQuestionDetail)
    {
        startPage();
        List<ExaQuestionDetail> list = exaQuestionDetailService.selectExaQuestionDetailList(exaQuestionDetail);
        return getDataTable(list);
    }

    /**
     * 导出题目信息列表
     */
    @PreAuthorize("@ss.hasPermi('exam:detail:export')")
    @Log(title = "题目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExaQuestionDetail exaQuestionDetail)
    {
        List<ExaQuestionDetail> list = exaQuestionDetailService.selectExaQuestionDetailList(exaQuestionDetail);
        ExcelUtil<ExaQuestionDetail> util = new ExcelUtil<ExaQuestionDetail>(ExaQuestionDetail.class);
        util.exportExcel(response, list, "题目信息数据");
    }

    /**
     * 获取题目信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(exaQuestionDetailService.selectExaQuestionDetailById(id));
    }

    /**
     * 新增题目信息
     */
    @PreAuthorize("@ss.hasPermi('exam:detail:add')")
    @Log(title = "题目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExaQuestionDetail exaQuestionDetail)
    {
        return toAjax(exaQuestionDetailService.insertExaQuestionDetail(exaQuestionDetail));
    }

    /**
     * 修改题目信息
     */
    @PreAuthorize("@ss.hasPermi('exam:detail:edit')")
    @Log(title = "题目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExaQuestionDetail exaQuestionDetail)
    {
        return toAjax(exaQuestionDetailService.updateExaQuestionDetail(exaQuestionDetail));
    }

    /**
     * 删除题目信息
     */
    @PreAuthorize("@ss.hasPermi('exam:detail:remove')")
    @Log(title = "题目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exaQuestionDetailService.deleteExaQuestionDetailByIds(ids));
    }
}
